<link href="<?php echo base_url(JS_PUBLIC);?>/fileuploader/fileuploader.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="<?php echo base_url(JS_PUBLIC);?>/fileuploader/fileuploader.js" ></script>
<script type="text/javascript" src="<?php echo base_url(JS_PUBLIC);?>/ckeditor/ckeditor.js" ></script>
<script>
$(document).ready(function(){
	var uploader_single = new qq.FileUploader({
        element: document.getElementById('img_uploader'),
        allowedExtensions: ['jpeg', 'jpg', 'png', 'bmp', 'gif'],
        action: '<?php echo base_url('admin/upload').'?type=news&id='.@$data->news_id.'&mode=simple';?>',
        debug: false,
        uploadButtonText: "Thay đổi ảnh đại diện",
        multiple: false,
        onSubmit: function() {
            $('#loading').show();
        },
        onComplete: function(id, fileName, responseJSON){
            console.log(responseJSON);
            if (responseJSON.success) {
                $('#img').attr('src', BASE_URL+responseJSON.url);
            } else {
                alert(responseJSON.msg);
            }
            $('#loading').hide();
        },
        uploadButtonText: "Thay đổi ảnh đại diện",
    });
    $('#img_uploader .qq-upload-button').css({width: '160px', padding: '5px'});
    $('.qq-upload-list').remove();
});
</script>
<form method="post" class="form-horizontal">
    <fieldset>
        <legend><?php echo isset($data) ? 'Sửa' : 'Thêm mới';?> tin tức</legend>
        <?php if (isset($error)):?>
            <div class="alert alert-error"><?php echo $error;?></div>
        <?php else :?>
            <?php if (isset($msg)):?><div class="alert alert-success"><?php echo $msg;?></div><?php endif;?>
        <?php endif;?>
        <div class="control-group">
            <label class="control-label" for="title">Tiêu đề tin tức</label>
            <div class="controls">
                <input type="text" class="input-xxlarge" name="title" id="title" value="<?php echo @$data->title;?>" />
            </div>
        </div>

        <div class="control-group">
            <label class="control-label" for="intro">Nhóm danh mục</label>
            <div class="controls"><?php echo form_dropdown('category', $category, @$data->category_id);?></div>
        </div>

        <div class="control-group">
            <label class="control-label" for="title">Ảnh đại diện</label>
            <div class="controls">
                <img id="img" onerror="ImgError(this);" width="170" height="150" src="<?php echo base_url('uploads/news/'.@$data->news_id.'/'.md5(@$data->news_id).'.jpg');?>" />
                <div id="img_uploader"></div>
            </div>
        </div>

        <div class="control-group">
            <label class="control-label" for="intro">Mô tả ngắn gọn</label>
            <div class="controls">
                <textarea name="intro" class="input-xxlarge" rows="5"><?php echo @$data->intro;?></textarea>
            </div>
        </div>

        <div class="control-group">
            <label class="control-label" for="description">Mô tả chi tiết</label>
            <div class="controls">
                <textarea name="content" class="input-xxlarge ckeditor" rows="5"><?php echo @$data->content;?></textarea>
            </div>
        </div>

        <div class="control-group">
            <div class="controls">
                <?php echo form_hidden('id', @$data->news_id); ?>
                <input type="submit" class="btn btn-primary" value="Lưu lại" />
                <input type="reset" class="btn" value="Bỏ qua" />
            </div>
        </div>
    </fieldset>
</form>